package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyOutParkVo;
import com.ruoyi.system.bo.ZsyyOutParkQueryBo;
import com.ruoyi.system.bo.ZsyyOutParkAddBo;
import com.ruoyi.system.bo.ZsyyOutParkEditBo;
import com.ruoyi.system.service.IZsyyOutParkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 对外开放停车场配置Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "对外开放停车场配置控制器", tags = {"对外开放停车场配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/outPark")
public class ZsyyOutParkController extends BaseController {

    private final IZsyyOutParkService iZsyyOutParkService;

    /**
     * 查询对外开放停车场配置列表
     */
    @ApiOperation("查询对外开放停车场配置列表")
    @PreAuthorize("@ss.hasPermi('system:outPark:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyOutParkVo> list(@Validated ZsyyOutParkQueryBo bo) {
        return iZsyyOutParkService.queryPageList(bo);
    }

    /**
     * 导出对外开放停车场配置列表
     */
    @ApiOperation("导出对外开放停车场配置列表")
    @PreAuthorize("@ss.hasPermi('system:outPark:export')")
    @Log(title = "对外开放停车场配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyOutParkVo> export(@Validated ZsyyOutParkQueryBo bo) {
        List<ZsyyOutParkVo> list = iZsyyOutParkService.queryList(bo);
        ExcelUtil<ZsyyOutParkVo> util = new ExcelUtil<ZsyyOutParkVo>(ZsyyOutParkVo.class);
        return util.exportExcel(list, "对外开放停车场配置");
    }

    /**
     * 获取对外开放停车场配置详细信息
     */
    @ApiOperation("获取对外开放停车场配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:outPark:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyOutParkVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyOutParkService.queryById(id));
    }

    /**
     * 新增对外开放停车场配置
     */
    @ApiOperation("新增对外开放停车场配置")
    @PreAuthorize("@ss.hasPermi('system:outPark:add')")
    @Log(title = "对外开放停车场配置", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyOutParkAddBo bo) {
        return toAjax(iZsyyOutParkService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改对外开放停车场配置
     */
    @ApiOperation("修改对外开放停车场配置")
    @PreAuthorize("@ss.hasPermi('system:outPark:edit')")
    @Log(title = "对外开放停车场配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyOutParkEditBo bo) {
        return toAjax(iZsyyOutParkService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除对外开放停车场配置
     */
    @ApiOperation("删除对外开放停车场配置")
    @PreAuthorize("@ss.hasPermi('system:outPark:remove')")
    @Log(title = "对外开放停车场配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyOutParkService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
